package model.components;

import java.awt.Rectangle;
import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Element;

import model.Camera;
import model.LayerEnum;
import model.MapEnum;

/**
 * @author thiago.barreto
 * @since 17/05/2011
 */
public class StageComponentFactory {

	Map<Integer, LayerEnum> layerMap = new HashMap<Integer, LayerEnum>();

	public StageComponentFactory(){
		for(LayerEnum value : LayerEnum.values()){
			layerMap.put(value.getCode(), value);
		}
	}

	/**
	 *
	 * @param element
	 * @return Um StageComponent de um elemento xml
	 */
	public StageComponent getComponent(Element element, MapEnum currentPart){
		StageComponent component = new StageComponent();
		int x = Integer.parseInt(element.getAttribute("x"));
		x = x - Camera.LEFT_LIMIT;
		int y = Integer.parseInt(element.getAttribute("y"));
		int width = Integer.parseInt(element.getAttribute("width"));
		int height = Integer.parseInt(element.getAttribute("height"));
		int layer = Integer.parseInt(element.getAttribute("layer"));
		component.setRegion(new Rectangle(x, y, width, height));
		component.setLayer(layerMap.get(layer));
		component.setName(element.getNodeName());
		component.setPart(currentPart);
		return component;
	}


}
